/**********************************************************/
/* Goblin Defense - A tower defense game for Wii Homebrew */
/* Copyright (C) 2009 Ricardo Bueno Cordeiro              */
/* Licensed under de GNU General Public License v2.0      */
/*   See license_gplv2.txt for detalis                    */
/**********************************************************/

#include <gccore.h>
#include <math.h>

#include "thrower.h"
#include "rock.h"
#include "../game.h"
#include "../map.h"
#include "../draw.h"
#include "../pony.h"

WeaponThrower::WeaponThrower(f32 xp, f32 yp) : x(xp), y(yp), throw_cool_time(0) {
}

void WeaponThrower::draw() {
	Sprite::draw_sprite(this->x, this->y, WEAPON_UPGRADABLE_SIZE, WEAPON_UPGRADABLE_SIZE, sprite_thrower);
}

void WeaponThrower::update(u32 step) {
	this->throw_cool_time += step;
}

int WeaponThrower::remove() {
	return 0;
}

f32 WeaponThrower::get_x() {
	return this->x;
}

f32 WeaponThrower::get_y() {
	return this->y;
}

f32 WeaponThrower::get_radius() {
	return 70.0;
}

int WeaponThrower::get_area_type() {
	return WEAPON_AREA_SINGLE;
}

void WeaponThrower::pony_near_by(Game *game, Pony *pony) {
	if (this->throw_cool_time < 1000)
		return;

	this->throw_cool_time = 0;

	f32 dir_x = pony->get_x() - this->get_x();
	f32 dir_y = pony->get_y() - this->get_y();
	f32 size = sqrt(dir_x * dir_x + dir_y * dir_y);

	Weapon *rock = new WeaponRock(this->get_x(), this->get_y(), dir_x / size, dir_y / size);
	game->get_map()->add_weapon(rock);
}

int WeaponThrower::get_position_type() {
	return WEAPON_POSITION_OFFPATH;
}

void WeaponThrower::draw_info() {
}

void WeaponThrower::click(f32 x, f32 y) {
}
